<?php
$section = 7;
include("includes/secure.php");
include("../includes/config.php");
include("../includes/class/school.class.php");
require_once("../includes/fckeditor/fckeditor_php5.php");
require_once("../includes/class/fileManagement.class.php");

$school = new School(); 
$file = new fileManagement();

$desc_es1 = new FCKeditor('descripcion');
	//$desc_es->ToolbarSet = "Basic";
	$desc_es1->ToolbarSet = "Default";
	$desc_es1->Height = "250";
	$desc_es1->Width = "750";
	

		
if(isset($_POST['add']) && $_POST['add'] == 1)
{
	$data->fecha 		= cambiarFormatoFecha($_POST['fecha'],2);
	$data->school    	= mysql_real_escape_string($_POST['school']);
	$data->tittle	    = mysql_real_escape_string($_POST['title']);
	$data->description	= mysql_real_escape_string($_POST['descripcion']);
	
		
	if(isset($_FILES['archivo']))
	{
		for($i=0;$i<sizeof($_FILES['archivo']['tmp_name']);$i++)
		{
			if(is_uploaded_file($_FILES['archivo']['tmp_name'][$i]))
			{
				$documento = $file->subirArchivo($_FILES['archivo']['tmp_name'][$i],$_FILES['archivo']['name'][$i],'../file_upload/documentos/');								 
				$data->original 	= $_FILES['archivo']['name'][$i];
				$data->renam        = $documento;						
			}
			
		}
	}
	
	if($id = $school->addSound($data))
	{	
		$exito = true;
			
			$members =  explode(",",$_POST['members']);
			
			
			
						
			for($i=0;$i<count($members);$i++)
			{	
				
				$dataMember->name 		= $members[$i];
				$dataMember->sound 	= $id;
				
				if(!$school->addDeveloment($dataMember))
				{
					$exito = false;
				}
			}	
			if($exito)
			{
				echo "<script>alert('Audio agregado con éxito')</script>";
				echo "<script>window.location.href='listSounds.php';</script>";	
			}
			else
			{
				echo "<script>alert('El Audio no se pudo agregar')</script>";
				echo "<script>window.location.href='listSounds.php';</script>";	
			}	
		
	}
	else
	{
		echo "<script>alert('El Audio no se pudo agregar')</script>";
				echo "<script>window.location.href='listSounds.php';</script>";	
	}
	
}
else
{
	$stringSchool = $school->listSchoolSelect();

}


?>
